package com.jtbd.service.impl.campus;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jtbd.domain.CustomerChildren;
import com.jtbd.domain.CustomerChildrenWithRelationItem;
import com.jtbd.service.campus.CustomerChildrenRelationService;
import com.jtbd.service.campus.CustomerChildrenService;
import com.jtbd.mapper.CustomerChildrenMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Administrator
 * @description 针对表【customer_children(客户孩子表)】的数据库操作Service实现
 * @createDate 2025-08-23 11:55:35
 */
@Service
public class CustomerChildrenServiceImpl extends ServiceImpl<CustomerChildrenMapper, CustomerChildren> implements CustomerChildrenService {
    @Resource
    private CustomerChildrenMapper customerChildrenMapper;
    @Resource
    private CustomerChildrenRelationService customerChildrenRelationService;


    @Override
    @Transactional
    public void addCustomerChildren(List<CustomerChildrenWithRelationItem> customerChildrens, Long customerId) {
        customerChildrens.forEach(item -> {
            item.getCustomerChildren().setCustomerId(customerId);
            customerChildrenMapper.insert(item.getCustomerChildren());
            item.getCustomerChildrenRelation().setCustomerId(customerId);
            item.getCustomerChildrenRelation().setChildrenId(item.getCustomerChildren().getId());
            customerChildrenRelationService.addCustomerChildrenRelation(item.getCustomerChildrenRelation());
        });
    }

    @Override
    public void addCustomerChildren(List<CustomerChildrenWithRelationItem> customerChildrens, Long customerId, Long operatorUserId) {
        customerChildrens.forEach(item -> {
            item.getCustomerChildren().setCreateId(operatorUserId);
            item.getCustomerChildren().setUpdateId(operatorUserId);
            item.getCustomerChildren().setCustomerId(customerId);
            customerChildrenMapper.insert(item.getCustomerChildren());
            item.getCustomerChildrenRelation().setCustomerId(customerId);
            item.getCustomerChildrenRelation().setChildrenId(item.getCustomerChildren().getId());
            customerChildrenRelationService.addCustomerChildrenRelation(item.getCustomerChildrenRelation());
        });
    }

    @Override
    public void updateCustomerChildren(List<CustomerChildrenWithRelationItem> customerChildrens, Long operatorUserId) {
        customerChildrens.forEach(item -> {
            item.getCustomerChildren().setUpdateId(operatorUserId);
            customerChildrenMapper.updateById(item.getCustomerChildren());
            customerChildrenRelationService.updateRelationById(item.getCustomerChildrenRelation());
        });
    }

    @Override
    public void updateCustomerChildrenItem(CustomerChildrenWithRelationItem item, Long operatorUserId) {
        item.getCustomerChildren().setUpdateId(operatorUserId);
        customerChildrenMapper.updateById(item.getCustomerChildren());
        customerChildrenRelationService.updateRelationById(item.getCustomerChildrenRelation());
    }
}




